admin: Add ot_admin_checksum_version to get a dup of the version for a commit
authorJames Antill <james@and.org>
Wed, 22 Oct 2014 05:21:14 +0000 (01:21 -0400)
committerColin Walters <walters@verbum.org>
Thu, 23 Oct 2014 14:21:17 +0000 (10:21 -0400)
src/ostree/ot-admin-functions.c
src/ostree/ot-admin-functions.h

index 34e5c6b235b8b5e743d2e41468091ce82ef0822d..ff6235745f4498c1c85ada0c0276b9bea413496c 100644 (file)
@@ -48,3 +48,26 @@ ot_admin_require_booted_deployment_or_osname (OstreeSysroot       *sysroot,
  out:
   return ret;
 }
+
+/**
+ * ot_admin_checksum_version:
+ * @checksum: A GVariant from an ostree checksum.
+ *
+ *
+ * Get the version metadata string from a commit variant object, if it exists.
+ *
+ * Returns: A newly allocated string of the version, or %NULL is none
+ */
+char *
+ot_admin_checksum_version (GVariant *checksum)
+{
+  gs_unref_variant GVariant *metadata = NULL;
+  const char *ret = NULL;
+
+  metadata = g_variant_get_child_value (checksum, 0);
+
+  if (!g_variant_lookup (metadata, "version", "&s", &ret))
+    return NULL;
+
+  return g_strdup (ret);
+}
index ab830369d0d52b3da90f8de4f0080d5b26b16f57..ea147c84adc378f538025d427efecc646e584137 100644 (file)
@@ -32,5 +32,9 @@ ot_admin_require_booted_deployment_or_osname (OstreeSysroot       *sysroot,
                                               const char          *osname,
                                               GCancellable        *cancellable,
                                               GError             **error);
+
+char *
+ot_admin_checksum_version (GVariant *checksum);
+
 G_END_DECLS